<%@ page language="java" import="java.util.*" import="java.sql.*" import="java.util.Date" import="java.text.SimpleDateFormat"
pageEncoding="utf-8"%>

    <%
    request.setCharacterEncoding("utf-8");
    String publisher=request.getParameter("publisher");
    String message_title=request.getParameter("message_title");
    String message_info=request.getParameter("message_info");
    String select=request.getParameter("select");
    Date time=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    String newtime=sdf.format(time);
    String img="img/robot.jpg";
     System.out.println(message_title+","+newtime+","+img+","+publisher+","+message_info);
     %>
     <%!
     int max;
     int num=0;
     String zhuangtai="未借出";
     String cno;
      %>
    <%
    	String driverClass1="com.mysql.jdbc.Driver";
	    String url1="jdbc:mysql://localhost:3306/vote?useSSL=false";
	    String user1="root";
	    String password1="womenilu2580";
	    Class.forName(driverClass1);
	    Connection conn1=DriverManager.getConnection(url1,user1,password1);	 
	    Statement stat1=conn1.createStatement();
	    String sql1="select max(id) as max,t_customer.cno from science,t_customer where cname='"+publisher+"'";
	    ResultSet rs1=stat1.executeQuery(sql1);  
	     while(rs1.next()){//得到总的记录数
	   		max=rs1.getInt("max");
	   		cno=rs1.getString("cno");
		 } 	System.out.println("max的值："+max);
	    
    	String driverClass="com.mysql.jdbc.Driver";
	    String url="jdbc:mysql://localhost:3306/vote?useSSL=false";
	    String user="root";
	    String password="womenilu2580";
	    Class.forName(driverClass);
	    Connection conn=DriverManager.getConnection(url,user,password);	 
	    String sql="insert into science values(?,?,?,?,?,?,?,?,?,?,?,?)";
	    PreparedStatement ps=conn.prepareStatement(sql);	   		
		ps.setString(1, message_title);
		ps.setString(2, newtime);
		ps.setString(3, img);
		ps.setString(4, publisher);
		ps.setString(5, message_info);
		ps.setString(6, zhuangtai);
		ps.setInt(7, max+1);
		ps.setString(8,select);
		ps.setString(9,cno);
		ps.setString(10,"NULL");
		ps.setString(11, "null");
		ps.setInt(12, num);
		int i=ps.executeUpdate();
		out.print("成功添加"+i+"行");
		ps.close();
		conn.close();
		
     %>
     <jsp:forward page="science.jsp?num=0"></jsp:forward>
